﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Jungle.Code.Core;
using Jungle.Code.Utils;
using Jungle.Rent;

using System.Xml;

public partial class SearchBox : System.Web.UI.UserControl
{
    private Language lang;
    private string[] langParams;
    XmlDocument langDoc = new XmlDocument();
    // ---------------------------------------------------------------------------------------
    protected override void OnInit(EventArgs e)
    {
        LoadLanguage();
        btn_Search.PostBackUrl = UrlHelper.GetSiteUrl() + "/" + lang.Name + "/offers.aspx?cmd=search";

        LoadDdls();

        base.OnInit(e);
    }
    // ----------------------------------------------------------------
    protected void LoadDdls()
    {
        foreach (ListItem l in Offer.ddl_Countrys().Items) { ddl_Country.Items.Add(new ListItem(ChangeParameterDdl(l.Text), l.Value)); }
        foreach (ListItem l in Offer.ddl_ObjectType().Items) { ddl_ObjectType.Items.Add(new ListItem(ChangeParameterDdl(l.Text), l.Value)); }
    }
    // -------------------------------------------------------------------------------
    private void LoadLanguage()
    {
        string ControlPath = "/Modules/OfferManager";
        int LangId = Node.GetByUrl(UrlHelper.GetRequestUrl().Substring(0, UrlHelper.GetRequestUrl().IndexOf(".aspx")).Replace("/main", "")).LangID;
        Language l = new Language(LangId, "", "", true, 0); l.GetById();
        lang = l;

        langDoc.Load(Context.Server.MapPath(ControlPath + "/langs/" + l.Name + ".xml"));
        langParams = new string[langDoc.ChildNodes[1].ChildNodes.Count];
        for (int i = 0; i < langDoc.ChildNodes[1].ChildNodes.Count; i++)
        {
            langParams[i] = langDoc.ChildNodes[1].ChildNodes[i].InnerText;
        }

        Label[] lbs = { p000, p001, p002, p003, p004, p005 };
        for(int i=0; i < lbs.Length; i++)
        {
            lbs[i].Text = langParams[i];
        }

        btn_Search.Text = langParams[6];
    }
    // -------------------------------------------------------------------------------
    private string ChangeParameterDdl(string input)
    {
        string output = input;
        foreach (XmlNode n in langDoc.ChildNodes[1].ChildNodes)
        {
            if (n.Name == input) output = n.InnerText;
        }
        return output;
    }
}
